package coreAuction;

import java.util.*;
public class Auction {
	ItemList items = new ItemList();
	CustomerList custs = new CustomerList();
	ArrayList<Bid> bidList = new ArrayList<Bid>();
	
	//////////////////////////////////////////////////////////
	//CONSTRUCTOR plus setup from hard coding
	public Auction() {
		setup();
	}
	
	private  void setup() {

		items.add(new Item("A4", "Grandfather Clock"));
		items.add(new Item("A5", "Armchair"));
		items.add(new Item("A6", "Bedside table"));
		items.add(new Item("B1", "Table Lamp"));
		items.add(new Item("B2", "Standard Lamp"));
		items.add(new Item("B3", "Chandelier"));
		

		custs.add(new Customer("43", "John"));
		custs.add(new Customer("44", "Jim"));
		custs.add(new Customer("45", "Jack"));
	}
	///////////////////////////////////////////////////////////
	
	public String getItemReport() {
		return items.getItemList();
	}

	
	public void processBids() {
		System.out.println("PROCESSING BIDS");
		Bid b = new Bid("B3", "43", 56, items, custs);
		bidList.add(b);
		b = new Bid("B1", "44", 46, items, custs);
		bidList.add(b);
		b = new Bid("B3", "44", 36, items, custs);
		bidList.add(b);
		b = new Bid("B3", "45", 66, items, custs);
		bidList.add(b);
		
		for (Bid bid : bidList){
			String report = processOneBid(bid);
			System.out.println(report);
		}
	}
	
	private String processOneBid(Bid b) {
		String report = "";
		b.getBidCust().addBid(b);
		Bid superceded = b.getBidItem().addBid(b);
		if (superceded != null)	{
			report += superceded.getReport() + "\n";
		}
		report += b.getReport();
		return report;
	}

	public String getBidReport() {
		String report = "FINAL BID REPORT\n";
		for (Bid b : bidList) {
			report += b.getReport() + "\n";
		}	
		return report;
	}
	
	public String getCustList() {
		return custs.getCustList();
	}
	public void reportOutcome() {
		System.out.println();
		System.out.println(getBidReport());
		System.out.println();
		System.out.println(items.getItemList());
		System.out.println();
		System.out.println(custs.getCustList());
	}	

}
